package com.example.demo.pattern.strategy;

import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

@Component
public class Context {

    private Map<String,Strategy> map;

    public Context(List<Strategy> strategyList) {
        map = strategyList.stream().collect(Collectors.toMap(a->a.getType(), Function.identity()));
    }

    public int executeStrategy(String type,int num1,int num2){
        int i = map.get(type).doOperate(num1, num2);
        System.out.println(i);
        return i;
    }
}
